<template>
  <div class="catalog_block" @click="handleClick">
    <div class="corner top_right"></div>
    <div class="corner top_left"></div>
    <div class="corner bottom_right"></div>
    <div class="corner bottom_left"></div>
    
    <div class="about_block__num">{{ id }}</div>
    
    <div class="catalog_block__ico">
      <img v-if="image" class="catalog_block__imglayout" :src="image" :alt="title">
      <span>{{ title }}</span>
    </div>
    
    <div class="catalog_block__hover">
      <div class="catalog_block__hover_in">
        <div v-if="description" class="pb_hover_text">
          {{ description }}
        </div>
        <div v-if="link" class="pb_link">
          {{ title }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';

const props = defineProps<{
  id: string;
  title: string;
  image?: string;
  description?: string;
  link?: string;
}>();

const router = useRouter();

const handleClick = () => {
  if (props.link) {
    // 如果是内部路由（以/catalog/开头），使用router.push
    if (props.link.startsWith('/catalog/')) {
      router.push(props.link);
    } else if (props.link !== '#') {
      // 如果是外部链接，在新标签页打开
      window.open(props.link, '_blank');
    }
  }
};
</script>

<style scoped>
/* 使用原网站的样式 */
.catalog_block {
  width: calc(33.333% - 4px);
  height: 29rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 2px;
  padding: 5px;
  transition: all 0.3s ease-in-out;
  cursor: pointer;
  overflow: hidden;
}

.catalog_block:hover .corner {
  opacity: 0;
}

.catalog_block:hover .catalog_block__hover {
  opacity: 1;
}

.catalog_block:hover .catalog_block__hover:before {
  width: 100%;
}

/* 四个角的装饰边框 - 默认黄色 */
.corner {
  position: absolute;
  width: 3rem;
  height: 3rem;
  transition: all 0.3s ease-in-out;
}

.corner.top_right {
  top: 0;
  right: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.corner.top_left {
  top: 0;
  left: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.07);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.corner.bottom_right {
  bottom: 0;
  right: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.corner.bottom_left {
  left: 0;
  bottom: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

/* 编号 - 左上角黄色背景 */
.about_block__num {
  background-color: #e58707;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  width: 3rem;
  height: 3rem;
  left: 5px;
  top: 5px;
  font-size: 1.4rem;
  color: #fff;
  font-weight: 600;
  text-transform: uppercase;
  z-index: 99;
  line-height: 1;
}

/* 图标和标题区域 */
.catalog_block__ico {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.catalog_block__imglayout {
  max-width: 150px;
  display: block;
  margin: 0 auto;
  min-height: 150px;
  width: auto;
}

.catalog_block__ico > span {
  color: white;
  text-align: center;
  margin-top: 15px;
  font-family: ProximaNova sb, sans-serif;
  font-size: 1.6rem;
  font-weight: bold;
  padding: 0 20px;
  line-height: 1.4;
}

/* 悬停层 */
.catalog_block__hover {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 99%;
  height: 99%;
  display: table;
  background-color: #232b39;
  box-shadow: 0 4rem 8rem rgba(17, 23, 36, 0.6);
  transition: 0.7s;
  opacity: 0;
  padding: 2rem;
  pointer-events: none;
  z-index: 10;
}

.catalog_block__hover:before {
  content: '';
  display: block;
  width: 0;
  height: 0.3rem;
  background: #e58707;
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  transition: 1.2s;
}

.catalog_block__hover_in {
  display: table-cell;
  vertical-align: middle;
}

.catalog_block__hover_in > :not(:last-child) {
  margin-bottom: 2rem;
}

.pb_hover_text {
  color: #FFFFFF;
  font-weight: bold;
  font-size: 1.6rem;
  text-align: center;
  line-height: 1.5;
}

.pb_link {
  color: #FFFFFF;
  font-weight: bold;
  font-size: 1.8rem;
  text-align: center;
  text-decoration: none;
  width: 100%;
  display: block;
  transition: all 0.3s ease-in-out;
}

.pb_link:hover {
  color: #e58707;
}

/* 响应式设计 */
@media screen and (max-width: 1499px) {
  .catalog_block {
    height: 22rem;
  }
  
  .catalog_block__imglayout {
    max-width: 120px;
    min-height: 120px;
  }
  
  .catalog_block__ico > span {
    font-size: 1.4rem;
    margin-top: 10px;
    padding: 0 15px;
  }
  
  .catalog_block__hover {
    padding: 1.5rem;
  }
  
  .pb_hover_text {
    font-size: 1.4rem;
  }
  
  .pb_link {
    font-size: 1.6rem;
  }
}

@media screen and (max-width: 767px) {
  .catalog_block {
    width: calc(50% - 4px);
  }
  
  .catalog_block__imglayout {
    max-width: 100px;
    min-height: 100px;
  }
  
  .catalog_block__ico > span {
    font-size: 1.3rem;
    padding: 0 10px;
  }
}

@media screen and (max-width: 700px) {
  .catalog_block {
    width: 50%;
  }
}

@media screen and (max-width: 400px) {
  .catalog_block {
    width: 100%;
  }
}
</style>

